The cost of forsaking C

Oz Nova
Bradfield
Published in
3 min readOct 4, 2016

--

The C programming language is not trendy. The most recent edition of the canonical C text (the excitingly named The C Programming Language) was published in 1988; C is so unfashionable that the authors have neglected to update it in light of 30 years of progress in software engineering. Everyone “has been meaning to” learn Rust or Go or Clojure over a weekend, not C. There isn’t even a cute C animal in C’s non-logo on a C decal not stuck to your laptop.

But Myles and I are not trendy people, so we insist that all of our students become fluent in C. A fresh class of C converts has just finished working through the K&R bible, making this a good time for me to reflect on why we deify this ancient tongue.

We give students four reasons for learning C:

  1. It is still one of the most commonly used languages outside of the Bay Area web/mobile startup echo chamber;
  2. C’s influence can be seen in many modern languages;
  3. C helps you think like a computer; and,
  4. Most tools for writing software are written in C (or C++)

The first is easy to dismiss if one likes the Bay Area web/mobile startup echo chamber, the second if one hates C’s influence on many more modern languages. Most engineers should take heed of reason three, although our students also learn computer architecture and at least one assembly language, so have a firm mental model of how computers actually compute. But reason four is hard to ignore.

Forsaking C means forsaking anything below the level of abstraction at which one happens to currently work. Those who work for instance as web developers forsake thoroughly understanding the browsers, operating systems and languages on top of which their own work stands.

Concretely:

Most of our students use interpreted languages with popular implementations written in C. One exercise we do is to write a Python bytecode interpreter to better understand stack machines and interpreted languages; doing so involves reading the CPython implementation closely. The ruby reference implementation is also written in C, and most JavaScript implementations are written in C++.

When learning about common data structures such as hashmaps and dynamic arrays, we need to either implement these ourselves in a language where we can think concretely about memory layout, or to read good implementations that do so. For a student to understand how a Python list or ruby array works, we have them either write a version from scratch or read the source of the standard library implementations—gaining the same level of understanding without diving into C is almost impossible.

Learning about operating systems would be much harder without C. The operating systems that we use are mostly written in C, the C standard library is tightly coupled to the syscall interface, and most resources dealing with operating systems concepts assume knowledge of C.

While it is certainly possible to learn about computer networking without being fluent in C, practitioners who need to understand their operating system’s TCP/IP stack will find themselves grasping for C.

Lastly most of the work we do with databases, key value stores, message queues and other distributed systems technologies mandates C, for performance reasons.

Many practicing software engineers do fine work without fully understanding the above. Routine work in a narrow domain may not demand foundational knowledge. But our students strive to do novel, high-impact work, and quickly find that a solid understanding of C is a prerequisite. If you have similar goals, I would encourage you to put aside that trendy new language for a few more weekends and brush up on good old C.

Interested in diving deeper? Bradfield runs a course Computer Architecture and the Hardware/Software Interface every 2–3 months.

--

--